import Router from 'vue-router';
import Vue from 'vue';

Vue.use(Router);

// 全局路由
const globalRouter = [
  { path: '/', component: () => import("@src/views/index.vue"), name: 'index', meta: { title: '主页', requireAuth: false } },
  { path: '/login', component: () => import("@src/views/login.vue"), name: 'login', meta: { title: '登录页', requireAuth: false } },
]

// 子路由
const mainRouter = [];

/**
 * 实例化路由
 */
const router = new Router({
  mode: 'hash',
  routes: globalRouter.concat(mainRouter)
});

/**
 * 路由拦截
 */
router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) {
    // window.sessionStorage.getItem('token') ? next() : next({ path: '/login' });
    next();
  } else {
    next();
  }
})



export default router;


